package com.fyzk.activity.prize;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tyjc.lottery.R;
import com.fyzk.utils.LotteryIDUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 2017/12/4.
 */

public class BeiDanPrizeAdapter extends BaseAdapter {

    private int rq_color;

    private Context context;
    private List<BeiDanPrizeBean.RacesBean> infors = new ArrayList<>();
    private int lotteryId;

    public BeiDanPrizeAdapter(Context context, List<BeiDanPrizeBean.RacesBean> infors, int lotteryId) {
        this.context = context;
        this.infors = infors;
        this.lotteryId = lotteryId;
    }

    @Override
    public int getCount() {
        return infors.size();
    }

    @Override
    public Object getItem(int i) {
        return infors.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        BeiDanPrizeBean.RacesBean infor = infors.get(i);
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.adapter_beidan_prize, null);
            holder.matchNum = view.findViewById(R.id.beidan_prize_matchNum_tv);
            holder.matchName = view.findViewById(R.id.beidan_prize_matchName_tv);
            holder.home = view.findViewById(R.id.beidan_prize_home);
            holder.away = view.findViewById(R.id.beidan_prize_away);
            holder.rq = view.findViewById(R.id.beidan_prize_rq);
            holder.vs = view.findViewById(R.id.beidan_prize_vs);
            holder.result = view.findViewById(R.id.beidan_prize_result);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        int leftBall = 0;
        try {
            leftBall = Integer.parseInt(infor.getHandicap());
        } catch (NumberFormatException e) {

        }
        if (leftBall > 0) {
            rq_color = context.getResources().getColor(R.color.color_FF4258);
        } else if (leftBall == 0) {
            rq_color = context.getResources().getColor(R.color.color_4EA5FF);
        } else {
            rq_color = context.getResources().getColor(R.color.color_47965a);
        }

        holder.matchNum.setText(infor.getMatchNum()+"");
        holder.matchName.setText(infor.getMatchName());
        holder.home.setText(infor.getHomeTeam());
        holder.away.setText(infor.getAwayTeam());
        holder.rq.setText("("+infor.getHandicap()+")");
        holder.rq.setTextColor(rq_color);
        holder.vs.setText(infor.getHomeScore()+" : "+infor.getAwayScore());
        String resultStr = infor.getSpfResult();
        switch (lotteryId) {
            case LotteryIDUtils.DCSPF_LOTTERY_ID_INT:
                resultStr = infor.getSpfResult();
                break;
            case LotteryIDUtils.DCBF_LOTTERY_ID_INT:
                resultStr = infor.getBfResult();
                break;
            case LotteryIDUtils.DCZJQ_LOTTERY_ID_INT:
                resultStr = infor.getJqsResult()+"球";
                break;
            case LotteryIDUtils.DCBQC_LOTTERY_ID_INT:
                resultStr = infor.getBqcResult();
                break;
            case LotteryIDUtils.DCSXDS_LOTTERY_ID_INT:
                resultStr = infor.getSxdsResult();
                break;
        }
        holder.result.setText(resultStr);

        return view;
    }

    public void setInfors(List<BeiDanPrizeBean.RacesBean> infors, int lotteryId) {
        this.lotteryId = lotteryId;
        this.infors = infors;
        this.notifyDataSetChanged();
    }

    class ViewHolder {
        TextView matchNum;
        TextView matchName;
        TextView home;
        TextView away;
        TextView rq;
        TextView vs;
        TextView result;
    }
}
